package com.piggy.logi.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.piggy.common.core.utils.PageUtils;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.logi.sys.service.ILogiSysNoticeService;
import com.piggy.logi.sys.domain.LogiSysNotice;
import com.piggy.logi.sys.mapper.LogiSysNoticeMapper;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 公告 服务层实现
 *
 * @author shark
 */
@Service
public class LogiSysNoticeServiceImpl extends ServiceImpl<LogiSysNoticeMapper, LogiSysNotice> implements ILogiSysNoticeService {

    @Override
    public TableDataInfo<LogiSysNotice> selectPageNoticeList(LogiSysNotice notice) {
        LambdaQueryWrapper<LogiSysNotice> lqw = new LambdaQueryWrapper<LogiSysNotice>()
                .like(StrUtil.isNotBlank(notice.getNoticeTitle()), LogiSysNotice::getNoticeTitle, notice.getNoticeTitle())
                .eq(StrUtil.isNotBlank(notice.getNoticeType()), LogiSysNotice::getNoticeType, notice.getNoticeType())
                .eq(notice.getDeptId() != null, LogiSysNotice::getDeptId, notice.getDeptId())
                .like(StrUtil.isNotBlank(notice.getCreateBy()), LogiSysNotice::getCreateBy, notice.getCreateBy());
        return PageUtils.buildDataInfo(page(PageUtils.buildPage(),lqw));
    }

    /**
     * 查询公告信息
     *
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
    public LogiSysNotice selectNoticeById(Long noticeId) {
        return getById(noticeId);
    }

    /**
     * 查询公告列表
     *
     * @param notice 公告信息
     * @return 公告集合
     */
    @Override
    public List<LogiSysNotice> selectNoticeList(LogiSysNotice notice) {
		return baseMapper.selectListNotice(notice.getDeptId(),notice.getNoticeTitle());
//        return list(new LambdaQueryWrapper<SysNotice>()
//                .like(StrUtil.isNotBlank(notice.getNoticeTitle()),SysNotice::getNoticeTitle,notice.getNoticeTitle())
//                .eq(StrUtil.isNotBlank(notice.getNoticeType()),SysNotice::getNoticeType,notice.getNoticeType())
//                .like(StrUtil.isNotBlank(notice.getCreateBy()),SysNotice::getCreateBy,notice.getCreateBy()));
    }

    /**
     * 新增公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int insertNotice(LogiSysNotice notice) {
        return baseMapper.insert(notice);
    }

    /**
     * 修改公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int updateNotice(LogiSysNotice notice) {
        return baseMapper.updateById(notice);
    }

    /**
     * 删除公告对象
     *
     * @param noticeId 公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long noticeId) {
        return baseMapper.deleteById(noticeId);
    }

    /**
     * 批量删除公告信息
     *
     * @param noticeIds 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] noticeIds) {
        return baseMapper.deleteBatchIds(Arrays.asList(noticeIds));
    }
}
